using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFramework;

namespace LS
{
    using GFUtility = GameFramework.Utility;

    /// <summary>
    /// 工程中的路径
    /// </summary>
    public static class LSPath
    {
        public static readonly string FileNameFormart = "{0}{1}";

        #region BaseName
        /// <summary>
        /// Unity工程资源目录的名称
        /// </summary>
        public static readonly string UnityProjectBaseName = "Assets";

        /// <summary>
        /// Unity工程目录中的编辑器目录名称
        /// </summary>
        public static readonly string UnityEditorBaseName = "Editor";

        /// <summary>
        /// 框架使用的编辑器资源目录名称
        /// </summary>
        public static readonly string LSEditorBaseName = "LSEditor";

        /// <summary>
        /// 框架使用的运行时资源目录名称
        /// </summary>
        public static readonly string LSRuntimeBaseName = "LSRuntime";

        /// <summary>
        /// 框架使用的存放资产的目录名称
        /// </summary>
        public static readonly string LSAssetsDirectoryName = "Assets";

        /// <summary>
        /// 框架使用的存放代码脚本的目录名称
        /// </summary>
        public static readonly string LSScriptsDirectoryName = "Scripts";

        public static readonly string LSPackageDirectoryName = "Packages";
        /// <summary>
        /// 模组目录名称
        /// </summary>
        public static readonly string LSModesName = "Mods";

        #endregion

        #region AssetDirectoryName
        public static readonly string LSConfigDirectoryName = "Configs";
        public static readonly string LSDataTableDirectoryName = "DataTables";
        public static readonly string LSLocalizationDirectoryName = "Localization";
        public static readonly string LSDictionariesDirectoryName = "Dictionaries";
        public static readonly string LSFontsDirectoryName = "Fonts";
        public static readonly string LSScenesDirectoryName = "Scenes";
        public static readonly string LSMusicDirectoryName = "Music";
        public static readonly string LSSoundsDirectoryName = "Sounds";
        public static readonly string LSEntityDirectoryName = "Entity";
        public static readonly string LSUIBaseDirectoryName = "UI";
        public static readonly string LSUIFormDirectoryName = "UIForms";
        public static readonly string LSUISoundDirectoryName = "UISounds";
        public static readonly string LSUIIconsDirectoryName = "Icons";
        public static readonly string LSTMPSpriteAssetDirectoryName = "SpriteAssets";
        #endregion

        #region LSPath
        /// <summary>
        /// 框架使用的运行时的资产路径 LSRuntime/Assets
        /// </summary>
        public static readonly string LSRuntimeAssetsPath = $"{LSRuntimeBaseName}/{LSAssetsDirectoryName}";

        /// <summary>
        /// 框架使用的运行时的代码脚本路径 LSRuntime/Scripts
        /// </summary>
        public static readonly string LSRuntimeScriptsPath = $"{LSRuntimeBaseName}/{LSScriptsDirectoryName}";

        /// <summary>
        /// 框架使用的编辑器的基础路径 Editor/LSEditor
        /// </summary>
        public static readonly string LSEditorBasePath = $"{UnityEditorBaseName}/{LSEditorBaseName}";

        /// <summary>
        /// 框架使用的编辑器资产目录地址 Editor/LSEditor/Assets
        /// </summary>
        public static readonly string LSEditorAssetsPath = $"{LSEditorBasePath}/{LSAssetsDirectoryName}";

        /// <summary>
        /// 框架使用的编辑器脚本路径 Editor/LSEditor/Scripts
        /// </summary>
        public static readonly string LSEditorScriptsPath = $"{LSEditorBasePath}/{LSScriptsDirectoryName}";
        #endregion

        #region UnityPath
        /// <summary>
        /// Unity工程目录下的编辑器基础路径 Assets/Editor/LSEditor
        /// </summary>
        public static readonly string UnityEditorBasePath = $"{UnityProjectBaseName}/{UnityEditorBaseName}";

        /// <summary>
        /// Unity工程目录下框架使用的运行时基础路径 Assets/LSRuntime
        /// </summary>
        public static readonly string UnityLSRuntimeBasePath = $"{UnityProjectBaseName}/{LSRuntimeBaseName}";

        /// <summary>
        /// Unity工程目录下框架使用的编辑器基础路径 Assets/Editor/LSEditor
        /// </summary>
        public static readonly string UnityLSEditorBasePath = $"{UnityProjectBaseName}/{LSEditorBasePath}";

        /// <summary>
        /// Unity工程目录下框架使用的运行时的资产路径 Assets/LSRuntime/Assets
        /// </summary>
        public static readonly string UnityLSRuntimeAssetsPath = $"{UnityProjectBaseName}/{LSRuntimeAssetsPath}";

        /// <summary>
        /// Unity工程目录下框架使用的运行时的代码脚本路径 Assets/LSRuntime/Scripts
        /// </summary>
        public static readonly string UnityLSRuntimeScriptsPath = $"{UnityProjectBaseName}/{LSRuntimeScriptsPath}";

        /// <summary>
        /// Unity工程目录下框架使用的编辑器资产目录地址 Assets/Editor/LSEditor/Assets
        /// </summary>
        public static readonly string UnityLSEditorAssetsPath = $"{UnityProjectBaseName}/{LSEditorAssetsPath}";

        /// <summary>
        /// Unity工程目录下框架使用的编辑器脚本路径 Editor/LSEditor/Scripts
        /// </summary>
        public static readonly string UnityLSEditorScriptsPath = $"{UnityProjectBaseName}/{LSEditorScriptsPath}";


        public static readonly string RuntimeModesPath = $"{Application.streamingAssetsPath}/{LSModesName}";


        #endregion

        #region LSAssetPath

        /// <summary>
        /// LSRuntime/Assets/Configs
        /// </summary>
        public static readonly string LSConfigAssetPath = $"{LSRuntimeAssetsPath}/{LSConfigDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/DataTables
        /// </summary>
        public static readonly string LSDataTablesAssetPath = $"{LSRuntimeAssetsPath}/{LSDataTableDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Localization
        /// </summary>
        public static readonly string LSLocalizationAssetPath = $"{LSRuntimeAssetsPath}/{LSLocalizationDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Fonts
        /// </summary>
        public static readonly string LSFontsAssetPath = $"{LSRuntimeAssetsPath}/{LSFontsDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Scenes
        /// </summary>
        public static readonly string LSScenesAssetPath = $"{LSRuntimeAssetsPath}/{LSScenesDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Music
        /// </summary>
        public static readonly string LSMusicAssetPath = $"{LSRuntimeAssetsPath}/{LSMusicDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Sounds
        /// </summary>
        public static readonly string LSSoundsAssetPath = $"{LSRuntimeAssetsPath}/{LSSoundsDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/Entity
        /// </summary>
        public static readonly string LSEntityAssetPath = $"{LSRuntimeAssetsPath}/{LSEntityDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/UI
        /// </summary>
        public static readonly string LSUIAssetPath = $"{LSRuntimeAssetsPath}/{LSUIBaseDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/UI/UIForms
        /// </summary>
        public static readonly string LSUIFormAssetPath = $"{LSUIAssetPath}/{LSUIFormDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/UI/UISounds
        /// </summary>
        public static readonly string LSUISoundAssetPath = $"{LSUIAssetPath}/{LSUISoundDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/UI/Icons
        /// </summary>
        public static readonly string LSUIIconsAssetPath = $"{LSUIAssetPath}/{LSUIIconsDirectoryName}";

        /// <summary>
        /// LSRuntime/Assets/UI/SpriteAssets
        /// </summary>
        public static readonly string LSTMPSpriteAssetAssetPath = $"{LSUIAssetPath}/{LSTMPSpriteAssetDirectoryName}";

        #endregion

        #region File Extension

        public const string TxtExtension = ".txt";
        public const string PrefabExtension = ".prefab";
        public const string UnityAssetExtension = ".asset";
        public const string SceneAssetExtension = ".unity";
        public const string PNGExtension = ".png";
        public const string JPGExtension = ".jpg";
        public const string JPEGExtension = ".jpeg";
        public const string TTFExtension = ".ttf";
        public const string XMLExtension = ".xml";
        public const string JsonExtension = ".json";
        public const string ByteExtension = ".bytes";
        public const string CsvExtension = ".csv";
        public const string KeystoreExtension = ".keystore";
        public const string MP3Extension = ".mp3";
        public const string MP4Extension = ".mp4";
        public const string WAVExtension = ".wav";
        public const string MOVExtension = ".mov";

        #endregion


        public static string FormatConfigAsset(string fileName,string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSConfigAssetPath}/{fileName}.{extension}";
            }
            return $"{LSConfigAssetPath}/{GFUtility.Text.Format(FileNameFormart,fileName,extension)}";
        }

        public static string FormatDataTableAsset(string fileName, string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSDataTablesAssetPath}/{fileName}.{extension}";
            }
            return $"{LSDataTablesAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatDictionaryAsset(string fileName, string extension, GameFramework.Localization.Language language)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSLocalizationAssetPath}/{language.ToString()}/{fileName}.{extension}";
            }
            return $"{LSLocalizationAssetPath}/{language.ToString()}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatFontAsset(string fileName, string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSFontsAssetPath}/{fileName}.{extension}";
            }
            return $"{LSFontsAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatScenesAsset(string fileName)
        {
            return $"{LSScenesAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, SceneAssetExtension)}";
        }

        public static string FormatMusicAsset(string fileName)
        {
            return $"{LSMusicAssetPath}/{fileName}";
        }

        public static string FormatSoundAsset(string fileName)
        {
            return $"{LSSoundsAssetPath}/{fileName}";
        }

        public static string FormatEntityAsset(string fileName)
        {
            return $"{LSEntityAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }

        public static string FormatUIFormAsset(string fileName)
        {
            return $"{LSUIFormAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }

        public static string FormatUISoundAsset(string fileName)
        {
            return $"{LSUISoundAssetPath}/{fileName}";
        }

        public static string FormatUIIconsAsset(string fileName,string extension)
        {
            return $"{LSUIIconsAssetPath}/{fileName}{extension}";
        }

        public static string FormatTMPSpriteAsset(string fileName)
        {
            return $"{LSTMPSpriteAssetAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }

        public static string FormatConfigUnityAsset(string fileName, string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSAssetsDirectoryName}/{LSConfigAssetPath}/{fileName}.{extension}";
            }
            return $"{LSAssetsDirectoryName}/{LSConfigAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatDataTableUnityAsset(string fileName, string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSAssetsDirectoryName}/{LSDataTablesAssetPath}/{fileName}.{extension}";
            }
            return $"{LSAssetsDirectoryName}/{LSDataTablesAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatDictionaryUnityAsset(string fileName, string extension, GameFramework.Localization.Language language)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSAssetsDirectoryName}/{LSLocalizationAssetPath}/{language.ToString()}/{fileName}.{extension}";
            }
            return $"{LSAssetsDirectoryName}/{LSLocalizationAssetPath}/{language.ToString()}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatFontUnityAsset(string fileName, string extension)
        {
            if (!extension.StartsWith("."))
            {
                return $"{LSAssetsDirectoryName}/{LSFontsAssetPath}/{fileName}.{extension}";
            }
            return $"{LSAssetsDirectoryName}/{LSFontsAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, extension)}";
        }

        public static string FormatScenesUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSScenesAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, SceneAssetExtension)}";
        }

        public static string FormatMusicUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSMusicAssetPath}/{fileName}";
        }

        public static string FormatSoundUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSSoundsAssetPath}/{fileName}";
        }

        public static string FormatEntityUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSEntityAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }

        public static string FormatUIFormUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSUIFormAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }

        public static string FormatUISoundUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSUISoundAssetPath}/{fileName}";
        }

        public static string FormatUIIconsUnityAsset(string fileName, string extension)
        {
            return $"{LSAssetsDirectoryName}/{LSUIIconsAssetPath}/{fileName}{extension}";
        }

        public static string FormatTMPSpriteUnityAsset(string fileName)
        {
            return $"{LSAssetsDirectoryName}/{LSTMPSpriteAssetAssetPath}/{GFUtility.Text.Format(FileNameFormart, fileName, PrefabExtension)}";
        }
    }
}
